<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>商户管理</cite></a>
        <a><cite>修改商户</cite></a>
    </div>
</div>
<style>
    .xxpayPopupDiv .layui-form-label {
        width:15% !important;
        margin-left:1%;
    }
    .xxpayPopupDiv .layui-input-inline {
        width: 33% !important;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <form class="layui-form layui-form-pane" enctype="multipart/form-data" type="post" >
            <div class="layui-tab layui-tab-brief">
                <ul class="layui-tab-title">
                    <li class="layui-this">基本信息</li>
                </ul>
                <input type="hidden" id="mchId" name="mchId" class="layui-input">
                <div class="layui-tab-content">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red">* </span>商户名称</label>
                        <div class="layui-input-inline">
                            <input type="text" id="name" name="name" lay-verify="required" placeholder="输入商户名" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">所属代理商</label>
                        <div class="layui-input-inline">
                            <select name="agentId" id="agentId" lay-search="">
		                      <option value="">请选择</option>
		                    </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red">* </span>用户名</label>
                        <div class="layui-input-inline">
                            <input type="text" id="userName" name="userName" placeholder="输入用户登录名" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label"><span style="color: red">* </span>手机号</label>
                        <div class="layui-input-inline">
                            <input type="tel" id="mobile" name="mobile" lay-verify="phone" placeholder="输入手机号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red">* </span>邮箱</label>
                        <div class="layui-input-inline">
                            <input type="text" id="email" name="email" lay-verify="email" placeholder="输入邮箱" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">身份证号</label>
                        <div class="layui-input-inline">
                            <input type="text" id="idCard" name="idCard" placeholder="输入身份证号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">QQ号</label>
                        <div class="layui-input-inline">
                            <input type="text" id="qq" name="qq" placeholder="输入QQ号" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">真实姓名</label>
                        <div class="layui-input-inline">
                            <input type="tel" id="realName" name="realName" placeholder="输入真实姓名" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">网站名称</label>
                        <div class="layui-input-inline">
                            <input type="text" id="siteName" name="siteName" placeholder="输入网站名称" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">网站地址</label>
                        <div class="layui-input-inline">
                            <input type="tel" id="siteUrl" name="siteUrl" placeholder="输入网站地址" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">通讯地址</label>
                        <div class="layui-input-inline">
                            <input type="text" id="address" name="address" placeholder="输入通讯地址" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">唯一标识</label>
                        <div class="layui-input-inline">
                            <input type="text" id="tag" name="tag" placeholder="输入唯一标识" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">线下充值费率(%)</label>
                        <div class="layui-input-inline">
                            <input type="text" id="offRechargeRate" name="offRechargeRate" lay-verify="number" placeholder="输入线下充值费率" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">商户状态</label>
                        <div class="layui-input-inline">
                            <input type="radio" name="status" value="1" title="启用" checked="checked">
                            <input type="radio" name="status" value="0" title="停止">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">是否上传附件信息</label>
                        <div class="layui-input-block">
                            <input type="checkbox" id="fileSwitch" lay-skin="switch" lay-filter="fileSwitch">
                        </div>
                    </div>
                </div>

                <ul class="layui-tab-title uploadFileDIV layui-hide">
                    <li class="layui-this">附件信息</li>
                </ul>
                <div class="layui-tab-content uploadFileDIV layui-hide">

                    <div class="layui-form-item">

                        <label class="layui-form-label"><span class="requiredSpan"> </span>身份证正面</label>
                        <div class="layui-input-inline">
                            <input class="imgVal uploadFileInput" fileType="1" type="hidden" />
                            <img class="uploadImg layui-hide" style="height:38px; margin-left:30px;cursor: pointer;" title="点击放大" />
                            <button class="uploadImgBtn layui-btn layui-btn-sm" type="button" style="margin-left: 20px;">上传图片</button>
                            <button class="delImgBtn layui-btn layui-btn-sm layui-btn-danger layui-hide" type="button">删除图片</button>
                        </div>

                        <label class="layui-form-label"><span class="requiredSpan"> </span>身份证反面</label>
                        <div class="layui-input-inline">
                            <input class="imgVal uploadFileInput" fileType="2" type="hidden" />
                            <img class="uploadImg layui-hide" style="height:38px; margin-left:30px;cursor: pointer;" title="点击放大" />
                            <button class="uploadImgBtn layui-btn layui-btn-sm" type="button" style="margin-left: 20px;">上传图片</button>
                            <button class="delImgBtn layui-btn layui-btn-sm layui-btn-danger layui-hide" type="button">删除图片</button>
                        </div>

                    </div>

                    <div class="layui-form-item">

                        <label class="layui-form-label"><span class="requiredSpan"> </span>手持身份证图片</label>
                        <div class="layui-input-inline">
                            <input class="imgVal uploadFileInput" fileType="3" type="hidden" />
                            <img class="uploadImg layui-hide" style="height:38px; margin-left:30px;cursor: pointer;" title="点击放大" />
                            <button class="uploadImgBtn layui-btn layui-btn-sm" type="button" style="margin-left: 20px;">上传图片</button>
                            <button class="delImgBtn layui-btn layui-btn-sm layui-btn-danger layui-hide" type="button">删除图片</button>
                        </div>

                        <label class="layui-form-label"><span class="requiredSpan"> </span>营业执照图片</label>
                        <div class="layui-input-inline">
                            <input class="imgVal uploadFileInput" fileType="4" type="hidden" />
                            <img class="uploadImg layui-hide" style="height:38px; margin-left:30px;cursor: pointer;" title="点击放大" />
                            <button class="uploadImgBtn layui-btn layui-btn-sm" type="button" style="margin-left: 20px;">上传图片</button>
                            <button class="delImgBtn layui-btn layui-btn-sm layui-btn-danger layui-hide" type="button">删除图片</button>
                        </div>
                    </div>

                    <div class="layui-form-item">

                        <label class="layui-form-label"><span class="requiredSpan"> </span>税务登记证图片</label>
                        <div class="layui-input-inline">
                            <input class="imgVal uploadFileInput" fileType="5" type="hidden" />
                            <img class="uploadImg layui-hide" style="height:38px; margin-left:30px;cursor: pointer;" title="点击放大" />
                            <button class="uploadImgBtn layui-btn layui-btn-sm" type="button" style="margin-left: 20px;">上传图片</button>
                            <button class="delImgBtn layui-btn layui-btn-sm layui-btn-danger layui-hide" type="button">删除图片</button>
                        </div>

                        <label class="layui-form-label"><span class="requiredSpan"> </span>考察照片</label>
                        <div class="layui-input-inline">
                            <input class="imgVal uploadFileInput" fileType="6" type="hidden" />
                            <img class="uploadImg layui-hide" style="height:38px; margin-left:30px;cursor: pointer;" title="点击放大" />
                            <button class="uploadImgBtn layui-btn layui-btn-sm" type="button" style="margin-left: 20px;">上传图片</button>
                            <button class="delImgBtn layui-btn layui-btn-sm layui-btn-danger layui-hide" type="button">删除图片</button>
                        </div>

                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="requiredSpan"> </span>商户协议图片</label>
                        <div class="layui-input-inline">
                            <input class="imgVal uploadFileInput" fileType="7" type="hidden" />
                            <img class="uploadImg layui-hide" style="height:38px; margin-left:30px;cursor: pointer;" title="点击放大" />
                            <button class="uploadImgBtn layui-btn layui-btn-sm" type="button" style="margin-left: 20px;">上传图片</button>
                            <button class="delImgBtn layui-btn layui-btn-sm layui-btn-danger layui-hide" type="button">删除图片</button>
                        </div>
                    </div>

                </div>


                <ul class="layui-tab-title">
                    <li class="layui-this">银行账号</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-form-item">
                        <label class="layui-form-label">开户行名称</label>
                        <div class="layui-input-inline">
                            <input type="text" id="bankName" name="bankName" placeholder="输入开户行名称" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">开户网点名称</label>
                        <div class="layui-input-inline">
                            <input type="text" id="bankNetName" name="bankNetName" placeholder="输入开户网点名称" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">账户名</label>
                        <div class="layui-input-inline">
                            <input type="text" id="accountName" name="accountName" placeholder="输入账户名称" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">账户号</label>
                        <div class="layui-input-inline">
                            <input type="text" id="accountNo" name="accountNo" placeholder="输入账户号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">开户所在省</label>
                        <div class="layui-input-inline">
                            <input type="text" id="province" name="province" placeholder="输入开户行所在省" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">开户所在市</label>
                        <div class="layui-input-inline">
                            <input type="text" id="city" name="city" placeholder="输入开户行所在市" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <ul class="layui-tab-title">
                    <li class="layui-this">安全信息</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-form-item">
                        <label class="layui-form-label">谷歌验证</label>
                        <div class="layui-input-inline">
                            <div id="googleAuthBind" style="display: none">
                                <input type="radio" title="已绑定" checked="checked" disabled>
                                <button type="button" class="layui-btn layui-btn-sm layui-btn-danger" id="untieGoogleAuth">解除绑定</button>
                            </div>
                            <div id="googleAuthNotBind" style="display: none; color: orangered">
                                <input type="radio" title="未绑定" checked="checked" disabled>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">登录安全类型</label>
                        <div class="layui-input-inline">
                            <select id="loginSecurityType" name="loginSecurityType" lay-verify="required">
                                <option value="1">仅登录密码验证</option>
                                <option value="2">登录密码+谷歌组合验证</option>
                            </select>
                        </div>
                        <label class="layui-form-label">支付安全类型</label>
                        <div class="layui-input-inline">
                            <select id="paySecurityType" name="paySecurityType" lay-verify="required">
                                <option value="0">无需验证</option>
                                <option value="1">仅支付密码验证</option>
                                <option value="2">仅谷歌验证</option>
                                <option value="3">支付密码+谷歌组合验证</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">登录密码</label>
                        <div class="layui-input-inline">
                            <input type="password" required name="password" placeholder="若修改请输入新密码,8-16位的字母和数字组合" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">支付密码</label>
                        <div class="layui-input-inline">
                            <input type="password" required name="payPassword" placeholder="若修改请输入新密码,8-16位的字母和数字组合" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">登录IP白名单</label>
                        <div class="layui-input-inline">
                            <textarea name="loginWhiteIp" id="loginWhiteIp" placeholder="请输入登录白名单,多个IP半角逗号分隔" class="layui-textarea"></textarea>
                        </div>
                        <label class="layui-form-label">登录IP黑名单</label>
                        <div class="layui-input-inline">
                            <textarea name="loginBlackIp" id="loginBlackIp" placeholder="请输入登录黑名单,多个IP半角逗号分隔" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">支付IP白名单</label>
                        <div class="layui-input-inline">
                            <textarea name="payWhiteIp" id="payWhiteIp" placeholder="请输入支付白名单,多个IP半角逗号分隔" class="layui-textarea"></textarea>
                        </div>
                        <label class="layui-form-label">支付IP黑名单</label>
                        <div class="layui-input-inline">
                            <textarea name="payBlackIp" id="payBlackIp" placeholder="请输入支付黑名单,多个IP半角逗号分隔" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">代付IP白名单</label>
                        <div class="layui-input-inline">
                            <textarea name="agentpayWhiteIp" id="agentpayWhiteIp" placeholder="请输入代付白名单,多个IP半角逗号分隔" class="layui-textarea"></textarea>
                        </div>
                        <label class="layui-form-label">代付IP黑名单</label>
                        <div class="layui-input-inline">
                            <textarea name="agentpayBlackIp" id="agentpayBlackIp" placeholder="请输入代付黑名单,多个IP半角逗号分隔" class="layui-textarea"></textarea>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">变更IP是否需要重新登录</label>
                        <div class="layui-input-block">
                            <input type="radio" name="ipChangeNeedReLogin" value="1" title="重新登录">
                            <input type="radio" name="ipChangeNeedReLogin" value="0" title="无需重新登录（不建议）">
                        </div>
                    </div>

                </div>

                <ul class="layui-tab-title">
                    <li class="layui-this">接口及接口安全配置项</li>
                </ul>
                <div class="layui-tab-content">

                    <div class="layui-form-item">
                        <label class="layui-form-label">商户API私钥</label>
                        <div class="layui-input-inline">
                            <textarea  oldKey="" name="privateKey" id="privateKey" placeholder="商户API私钥信息" class="layui-textarea layui-bg-gray" readonly ></textarea>
                        </div>
                        <a class="layui-btn layui-btn-normal layui-btn-xs" id="modifyKeyBtn" style="margin-bottom: 10px">修改KEY</a> <br/>
                        <a class="layui-btn layui-btn-warm layui-btn-xs layui-hide" id="randomGenKeyBtn" style="margin-bottom: 10px">随机生成</a>   <br/>
                        <a class="layui-btn layui-btn-primary layui-btn-xs layui-hide" id="resetKeyBtn" style="margin-bottom: 10px">恢复原始KEY</a>  <br/>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">商户代付模式</label>
                        <div class="layui-input-inline">
                            <select id="agentpayMode" name="agentpayMode" lay-verify="required">
                                <option value="1">仅代付接口</option>
                                <option value="2">仅后台接口</option>
                                <option value="3">接口 + 后台</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">代付接口二次确认</label>
                        <div class="layui-input-inline">
                            <input type="radio" name="agentpayAPIConfirmFlag" value="0" title="无需确认" checked="checked" lay-filter="agentpayAPIConfirmFilter">
                            <input type="radio" name="agentpayAPIConfirmFlag" value="1" title="需要确认" lay-filter="agentpayAPIConfirmFilter">
                        </div>
                    </div>
                    <fieldset class="layui-elem-field xxpayPopupDiv" id="agentpaySetJsonDiv">
                        <legend><button class="layui-btn layui-btn-xs layui-btn-danger">二次确认参数</button></legend>
                        <div class="layui-form-item">
                            <label class="layui-form-label">代付接口二次确认地址</label>
                            <div class="layui-input-inline">
                                <input name="agentpayAPIConfirmUrl" id="agentpayAPIConfirmUrl" placeholder="代付接口商户确认地址,请以http://或https://开头" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">商户订单号（参数名）</label>
                            <div class="layui-input-inline">
                                <input name="mchOrderNo" id="mchOrderNo" value="mchOrderNo" placeholder="发送的商户订单号参数名" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">代付金额（参数名）</label>
                            <div class="layui-input-inline">
                                <input name="amount" id="amount" value="amount" placeholder="发送的金额参数名" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">成功回调返回值</label>
                            <div class="layui-input-inline">
                                <input name="notifySuccessStatus" value="ok" id="notifySuccessStatus" placeholder="成功回调返回值" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">失败回调返回参数</label>
                            <div class="layui-input-inline">
                                <input name="notifyFailStatus" value="fail" id="notifyFailStatus" placeholder="失败回调返回参数" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </fieldset>

                    <p style="color: red"> 1. 当选择 [需要确认] 后，商户每次通过API接口形式发起的代付订单，会先通过接口推送到商户系统进行二次确认，确认无误后再继续执行代付任务。 如接口异常或拒绝则直接代付失败；</p>
                    <p style="color: red"> 2. 选择[需要确认]后， 请务必填写二次确认地址；</p>

                </div>
                <button class="layui-hide xxpayYesBtn" lay-submit lay-filter="mchEdit">保存</button>
            </div>
        </form>
    </div>
</div>

<script>
    layui.use(['admin', 'form', 'upload', 'setter'],function(){
        var form = layui.form
        ,$ = layui.$
        ,admin = layui.admin
        ,element = layui.element
        ,layer = layui.layer
        ,view = layui.view
        ,upload = layui.upload
        ,setter = layui.setter;

        // 导航
        element.render('breadcrumb', 'breadcrumb');
        var mchId = view.getOpenParams('mchId');
        
        admin.req({
            type: "POST",
            url: layui.setter.baseUrl + '/agent_info/getParentAgentId',
            success: function(res){
                if(res.code == 0) {
                	var agentList = res.data;
                	//遍历赋值
			        for(var i in agentList){
			        	if(agentList[i].agentLevel == 1){
			            	$("#agentId").append('<option value= '+agentList[i].agentId+'>'+ '[总代理]  ' +agentList[i].agentName +'</option>');
			        	}else if (agentList[i].agentLevel == 2){
			        		$("#agentId").append('<option value= '+agentList[i].agentId+'>'+ '[商户代理]  ' +agentList[i].agentName +'</option>');
			        	}
			        }
			        form.render('select');
			        admin.req({
                        type: 'get',
                        url: layui.setter.baseUrl + '/mch_info/get',
                        data: {
                            mchId : mchId
                        },
                        error: function(err){
                            layer.alert(JSON.stringify(err.field), {
                                title: '错误提示'
                            })
                        },
                        success: function(res){
                            if(res.code == 0){
                                $('#mchId').val(res.data.mchId);
                                $('#name').val(res.data.name);
                                $('#userName').val(res.data.userName);
                                $('#realName').val(res.data.realName);
                                $('#idCard').val(res.data.idCard);
                                $('#mobile').val(res.data.mobile);
                                $('#qq').val(res.data.qq);
                                $('#email').val(res.data.email);
                                $('#siteName').val(res.data.siteName);
                                $('#siteUrl').val(res.data.siteUrl);
                                $("input[name='type'][value='"+res.data.type+"']").attr("checked",true);
                                $("input[name='status'][value='"+res.data.status+"']").attr("checked",true);
                                $('#agentId').val(res.data.agentId ? res.data.agentId : "");
                                $('#address').val(res.data.address);
                                $('#tag').val(res.data.tag);
                                $('#offRechargeRate').val(res.data.offRechargeRate);
                                $('#bankName').val(res.data.bankName);
                                $('#bankNetName').val(res.data.bankNetName);
                                $('#accountName').val(res.data.accountName);
                                $('#accountNo').val(res.data.accountNo);
                                $('#province').val(res.data.province);
                                $('#city').val(res.data.city);
                                if(res.data.googleAuthStatus == 1) {
                                    $("#googleAuthBind").show();
                                    $("#googleAuthNotBind").hide();
                                }else {
                                    $("#googleAuthBind").hide();
                                    $("#googleAuthNotBind").show();
                                }
                                $("#loginSecurityType option[value='"+res.data.loginSecurityType+"']").attr("selected", true);
                                $("#paySecurityType option[value='"+res.data.paySecurityType+"']").attr("selected", true);
                                $('#loginWhiteIp').val(res.data.loginWhiteIp);
                                $('#loginBlackIp').val(res.data.loginBlackIp);
                                $('#payWhiteIp').val(res.data.payWhiteIp);
                                $('#payBlackIp').val(res.data.payBlackIp);
                                $('#agentpayWhiteIp').val(res.data.agentpayWhiteIp);
                                $('#agentpayBlackIp').val(res.data.agentpayBlackIp);

                                //商户私钥信息
                                $('#privateKey').val(res.data.privateKey).attr('oldKey', res.data.privateKey);

                                //代付模式
                                $("#agentpayMode option[value='"+res.data.agentpayMode+"']").attr("selected", true);
                                $("input[name='agentpayAPIConfirmFlag'][value='"+res.data.agentpayAPIConfirmFlag+"']").attr("checked", true); //代付二次确认状态
                                $('#agentpayAPIConfirmUrl').val(res.data.agentpayAPIConfirmUrl); //代付二次确认URL

                                if (res.data.agentpayAPIConfirmFlag == '0') {
                                    $("#agentpaySetJsonDiv").hide();
                                } else {
                                    $("#agentpaySetJsonDiv").show();
                                }

                                if (res.data.agentpayAPIConfirmJson) {
                                    var agentpayAPIConfirmJson = JSON.parse(res.data.agentpayAPIConfirmJson);
                                    if (agentpayAPIConfirmJson.mchOrderNo) {
                                        $("#mchOrderNo").val(agentpayAPIConfirmJson.mchOrderNo);
                                    }
                                    if (agentpayAPIConfirmJson.amount) {
                                        $("#amount").val(agentpayAPIConfirmJson.amount);
                                    }
                                    if (agentpayAPIConfirmJson.notifySuccessStatus) {
                                        $("#notifySuccessStatus").val(agentpayAPIConfirmJson.notifySuccessStatus);
                                    }
                                    if (agentpayAPIConfirmJson.notifyFailStatus) {
                                        $("#notifyFailStatus").val(agentpayAPIConfirmJson.notifyFailStatus);
                                    }
                                }

                                $("input[name='ipChangeNeedReLogin'][value='"+res.data.ipChangeNeedReLogin+"']").attr("checked", true);

                                form.render();

                                //获取商户附件信息
                                admin.req({
                                    type: 'get',
                                    url: layui.setter.baseUrl + '/mch_info/attachements',
                                    data: { mchId : mchId},
                                    error: function(err){
                                        layer.alert(JSON.stringify(err.field), {title: '错误提示'})
                                    },
                                    success: function(res){
                                        if(res.code == 0){

                                            if(!res.data || res.data.length <= 0 ){  return false; } //没有附件信息

                                            $.each(res.data, function(){ //处理图片
                                               setImgValFunc(this['fileType'], this['filePath']);
                                            });

                                            $("#fileSwitch").attr('checked', true);  //默认选中
                                            $('.uploadFileDIV').removeClass('layui-hide'); //显示
                                            form.render();
                                        }
                                    }
                                });
                            }
                        }
                    });
                }
            }
        });
        

        // 解除谷歌绑定
        $('#untieGoogleAuth').click(function() {
            layer.confirm('确认解绑该用户谷歌验证么?', function(index){
                admin.req({
                    type: "POST",
                    url: layui.setter.baseUrl + '/mch_info/google_untie',
                    data: {
                        mchId : mchId
                    },
                    success: function(res){
                        if(res.code == 0) {
                            layer.alert(res.msg, {title: "提示"}, function(index){
                                layer.close(index);
                                $("#googleAuthBind").hide();
                                $("#googleAuthNotBind").show();
                            });
                        }
                    }
                });
                layer.close(index);
            });
        });


        //监听 【是否上传文件附件】 选项
        form.on('switch(fileSwitch)', function(data){

            if(data.elem.checked){ //选择上传

                $('.uploadFileDIV').removeClass('layui-hide');

            }else{  //不上传
                $('.uploadFileDIV').addClass('layui-hide');
                $.each($('input[type="file"]'), function(){
                    delFile($(this).attr('id'));
                });
            }
        });


        form.on('submit(mchEdit)', function(data) {
            var amount = $.trim($('#amount').val());
            var mchOrderNo = $.trim($('#mchOrderNo').val());
            var notifySuccessStatus = $.trim($('#notifySuccessStatus').val());
            var notifyFailStatus = $.trim($('#notifyFailStatus').val());
            var agentpayAPIConfirmUrl = $.trim($('#agentpayAPIConfirmUrl').val());
            var agentpayAPIConfirmFlag = $('input[name="agentpayAPIConfirmFlag"]:checked ').val();
            if(agentpayAPIConfirmFlag == 1) {
                if(agentpayAPIConfirmUrl == '') {
                    layer.alert("请输入代付接口二次确认地址",{title: '提示'});
                    return false;
                }
                if(!agentpayAPIConfirmUrl.startsWith("http")) {
                    layer.alert("请输入正确的代付接口二次确认地址",{title: '提示'});
                    return false;
                }
                if (mchOrderNo == "") {
                    layer.alert("请输入商户订单号参数名",{title: '提示'});
                    return false;
                }
                if (amount == "") {
                    layer.alert("请输入代付金额参数名",{title: '提示'});
                    return false;
                }
                if (notifySuccessStatus == "") {
                    layer.alert("请输入成功回调返回参数",{title: '提示'});
                    return false;
                }
                if (notifyFailStatus == "") {
                    layer.alert("请输入失败回调返回参数",{title: '提示'});
                    return false;
                }
            }

            //构造上传文件数组参数
            let uploadFileArray = [];
            for(let i = 0 ; i < $(".uploadFileInput").length; i ++){
                let fileItem = $(".uploadFileInput").eq(i);
                if(fileItem.val()){
                    uploadFileArray.push({"fileType": fileItem.attr('fileType'), "filePath": fileItem.val() });
                }
            }
            data.field.uploadFileArrayStr = JSON.stringify(uploadFileArray);

            //这里可以写ajax方法提交表单
            admin.req({
                type: "POST",
                url: layui.setter.baseUrl + '/mch_info/update',
                data: data.field,
                success: function(res){
                    if(res.code == 0) {
                        layer.alert(res.msg, {title: "提示"}, function(index){

                            layer.closeAll(); //关闭所有弹层
                            layui.table.reload('tableReload'); //调用业务弹层外表格重新加载

                        });
                    }
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        //上传图片接口
        var headers = {};
        headers[setter.request.tokenName] = layui.data(setter.tableName)[setter.request.tokenName];
        upload.render({
            url: layui.setter.baseUrl + '/upload/putImg?'+setter.request.tokenName+"="+layui.data(setter.tableName)[setter.request.tokenName]
            , elem: '.uploadImgBtn'
            , headers: headers
            , size: 2048  //仅支持2M图片上传
            ,done: function(res, index, upload){

                //如果上传失败
                if(res.code != 0){
                    return layer.msg('上传失败['+res.msg+']', {icon: 2});
                }
                var divElem = $(this.item).parent();
                divElem.find('.imgVal').val(res.data); //图片真实路径
                divElem.find('.uploadImg').attr("src", res.data).removeClass('layui-hide');
                divElem.find('.delImgBtn').removeClass('layui-hide');
                divElem.find('.uploadImgBtn').text('重新上传');
                form.render();
            }
        });

        //点击[删除图片] 按钮， 事件
        $('.delImgBtn').click(function(){

            var divElem = $(this).parent();
            divElem.find('.imgVal').val(""); //清空图片真实路径
            divElem.find('.uploadImgBtn').text("上传图片");
            divElem.find('.uploadImg').attr("src", "").addClass('layui-hide');
            divElem.find('.delImgBtn').addClass('layui-hide');
            form.render();
        });

        //点击[图片] 按钮， 事件
        $('body').on('click', '.uploadImg', function(){
            var imgSrc = $(this).attr('src');
            layer.photos({photos: {
                    "title": "查看上传图片", //相册标题
                    "id": 1, //相册id
                    "start": 0, //初始显示的图片序号，默认0
                    "data": [   //相册包含的图片，数组格式
                        {
                            "alt": "图片",
                            "pid": 1, //图片id
                            "src": imgSrc, //原图地址
                            "thumb": "" //缩略图地址
                        }
                    ]
                } ,anim: 5});
        });

        var setImgValFunc = function(fileType, src){

            let inputObject = $(".uploadFileInput[fileType='"+fileType+"']");
            var divElem = inputObject.parent();
            divElem.find('.imgVal').val(src); //图片真实路径
            divElem.find('.uploadImg').attr("src", src).removeClass('layui-hide');
            divElem.find('.delImgBtn').removeClass('layui-hide');
            divElem.find('.uploadImgBtn').text('重新上传');
        }

        //点击修改key按钮事件
        $("#modifyKeyBtn").click(function(){

            $("#modifyKeyBtn").addClass('layui-hide');
            $("#randomGenKeyBtn").removeClass('layui-hide');
            $("#privateKey").removeClass('layui-bg-gray').removeAttr('readonly');
            form.render();
        });

        //随机生成key
        $("#randomGenKeyBtn").click(function(){
            $('#privateKey').val(randomWord(false, 128));
            $("#resetKeyBtn").removeClass('layui-hide');
            form.render();
        });

        //恢复key
        $("#resetKeyBtn").click(function(){
            $('#privateKey').val($('#privateKey').attr('oldKey'));
            form.render();
        });

        form.on('radio(agentpayAPIConfirmFilter)', function (data) {
            if (data.value == '0') {
                $("#agentpaySetJsonDiv").hide();
            } else {
                $("#agentpaySetJsonDiv").show();
            }
        });

        /**
         * 随机生成密钥
         * @param randomFlag
         * @param min
         * @param max
         * @returns {string}
         */
        function randomWord(randomFlag, min, max){
            var str = "",
                range = min,
                arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];

            // 随机产生
            if(randomFlag){
                range = Math.round(Math.random() * (max-min)) + min;
            }
            for(var i=0; i<range; i++){
                pos = Math.round(Math.random() * (arr.length-1));
                str += arr[pos];
            }
            return str;
        }


    })
</script>